//
//  TimerCell.swift
//  XingCeHelper
//
//  Created by 申铭 on 2022/11/16.
//

import UIKit
import ETKit

let kTimerCell: String = "TimerCell"

class TimerCell: BaseTableViewCell {

    @IBOutlet weak var nameLabel: UILabel!
    @IBOutlet weak var colorView: UIView!
    @IBOutlet weak var detailLabel: UILabel!
    
    var timer: CustomTimer? {
        didSet {
            nameLabel.text = timer?.name
            colorView.backgroundColor = timer?.color
            detailLabel.text = getDetailContent()
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        colorView.setFillet(cornerRadius: 8)
        nameLabel.font = UIFont.boldSystemFont(ofSize: 16)
    }
    
    private func getDetailContent() -> String {
        var typeName = ""
        if timer?.type == TimerType.timer.id {
            typeName = "纯计时"
        } else if timer?.type == TimerType.timeSlotTiming.id {
            typeName = "时间段"
            let format = "HH:mm"
            if let start = timer?.startTime.et.formatTime(format),
                let end = timer?.endTime.et.formatTime(format) {
                typeName = "\(typeName) | \(start) ~ \(end)"
            }
        } else if timer?.type == TimerType.countDown.id {
            typeName = "倒计时"
            if let s = timer?.duration.et.formatHMS(sh: false, sm: true, ss: false) {
                typeName = "\(typeName) | \(s)"
            }
        }
        
        return typeName
    }
    
}
